package com.jonychen.swagger2demo.controller;

import com.jonychen.swagger2demo.common.config.extend.ApiError;
import com.jonychen.swagger2demo.common.entity.model.User;
import com.jonychen.swagger2demo.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * @Description:用户信息管理类
 * @Author: kui.chen@100credit.com
 * @Date: 2019/9/6 14:53
 */
@Controller
@RequestMapping(value = "/user",produces = MediaType.APPLICATION_JSON_VALUE)
@Api(value = "/user",tags = "user api", description = "用户信息管理类 - 包括增、删、改、查和其他管理操作")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping(value = "/createUser", method= {GET, POST},produces = "text/plain;charset=UTF-8")
    @ApiOperation(value = "创建用户", notes = "根据传进来的参数创建一个用户", response = User.class)
    @ApiResponses({@ApiResponse(code = 500, message = "服务器内部错误", response = ApiError.class)})
    @ResponseBody
    public User createUser(
            @RequestBody @ApiParam(value = "创建的用户对象", required = true) User user) {
        return user;
    }

    @RequestMapping(value = "/updateUser", method = POST)
    @ApiOperation(value = "更新用户", notes = "根据传进来的参数更新用户的信息", response = String.class)
    @ApiResponses({@ApiResponse(code = 200, message = "更新成功", response = ApiError.class)})
    @ResponseBody
    public String updateUser(
            @RequestBody @ApiParam(value = "更新的用户对象", required = true) User user) {
        return "SUCCESS";
    }

    @RequestMapping(value = "/deleteUser/{username}", method = GET)
    @ApiOperation(value = "删除用户", notes = "根据用户名称删除用户", response = String.class)
    @ApiResponses(value = { @ApiResponse(code = 404, message = "删除失败") })
    @ResponseBody
    public String deleteUser(
            @ApiParam(value = "要删除用户的用户名称", required = true)
            @PathVariable("username") String username) {
        return "SUCCESS";

    }

    @RequestMapping(value = "/getUserByName/{username}", method = GET)
    @ApiOperation(value = "根据用户名称查询用户", notes = "根据用户名称查询用户")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 404, message = "查询失败")
    })
    @ResponseBody
    public List<User> getUserByName(
            @ApiParam(value = "要查询用户的用户名称", required = true)
            @PathVariable("username") String username) {
        List<User> userList = new ArrayList<>();
        userList.add(new User());
        return userList;
    }

    @RequestMapping(value = "/getUserById/{id}", method = GET)
    @ApiOperation(value = "根据用户id查询用户", notes = "根据用户id查询用户", response = User.class)
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 404, message = "查询失败")
    })
    @ResponseBody
    public User getUserById(
            @ApiParam(value = "要查询用户的用户id", required = true)
            @PathVariable("id") String id) {
        return new User();
    }

}

